package com.yuncheng.spcyApi.spcy;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.bo.*;
import com.yuncheng.spcyApi.busService.*;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.constant.other.YwlxmbConstant;
import com.yuncheng.spcyApi.constant.wjml.WjmlConstant;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.spcyApi.flow.FlowVo;
import com.yuncheng.spcyApi.flow.SpcyFlowConstant;
import com.yuncheng.spcyApi.flow.SpcyFlowService;
import com.yuncheng.spcyApi.mapper.SpcyFlowMapper;
import com.yuncheng.spcyApi.mapper.SpcySqsxBaiscMapper;
import com.yuncheng.spcyApi.mapper.SpcySqsxJobMapper;
import com.yuncheng.spcyApi.mapper.YcSysUserMapper;
import com.yuncheng.spcyApi.selectXzxkApi.service.PutZwxtService;
import com.yuncheng.spcyApi.service.ISpcyRsWjmbZjmlService;
import com.yuncheng.spcyApi.spcyService.*;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.spcyApi.utils.IpRateLimiterUtils;
import com.yuncheng.spcyApi.utils.StringPatternUtils;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.spcyApi.vo.common.Result;
import com.yuncheng.spcyApi.vo.fg.FgWtVo;
import com.yuncheng.spcyApi.vo.hbjc.HbSelectQyWjVo;
import com.yuncheng.spcyApi.vo.spcy.SpcyFlowVo;
import com.yuncheng.spcyApi.vo.spcy.SpcyReturnVo;
import com.yuncheng.spcyApi.vo.sqsx.HandXcjcwtTkVo;
import com.yuncheng.spcyApi.vo.sqsx.SqsxSaveVo;
import com.yuncheng.spcyApi.vo.sqsx.XcjcQyFileZipVo;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

@Api(tags = "审评查验接口")
@RestController
@RequestMapping("/api/spzx-spcy/spcy")
public class SpcyController {

    @Resource
    @Lazy
    private SpcyBlgcclService spcyBlgcclService;

    @Resource
    private SpcyFlowMapper spcyFlowMapper;

    @Resource
    private SpcySqsxJobMapper spcySqsxJobMapper;

    @Resource
    private SqsxQywjclService sqsxQywjclService;

    @Resource
    private SpcyService spcyService;

    @Resource
    private SpcyFlfgService spcyFlfgService;

    @Resource
    private SpcyFlowService spcyFlowService;

    @Resource
    private InitWjjlService initWjjlService;

    @Resource
    private YwlxmbService ywlxmbService;

    @Resource
    private YcSysUserMapper ycSysUserMapper;

    @Resource
    private SpcySqsxBaiscMapper spcySqsxBaiscMapper;

    @Resource
    private ISpcyRsWjmbZjmlService spcyRsWjmbZjmlService;

    @Resource
    private PutZwxtService putZwxtService;

    /**********************************************【 审评查验流程 】***********************************************************/

    @Log(title = "企业待办事项-分页查询")
    @ApiOperation(value = "企业待办事项-分页查询")
    @GetMapping("flowJobQyPage")
    public HttpResult<?> flowJobQyPage(SpcyFlowVo spcyFlowVo, PageVo pageVo, OrderItemVo orderItemVo){

        // 判断当前用户是否为企业
        String fqyid = ycSysUserMapper.findFqyidById(GetCurrentUserUtils.getCurrentUserId());
        fqyid = StringUtils.isNotBlank(fqyid) ? fqyid : "QYID123";

        spcyFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        spcyFlowVo.setFqyid(fqyid);
        spcyFlowVo.setFdbrid(fqyid);

        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        IPage<SpcyFlowVo> list = spcyFlowMapper.flowQyJobPage(page, spcyFlowVo, orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "事项监控-分页查询")
    @ApiOperation(value = "事项监控-分页查询")
    @GetMapping("flowJkPage")
    public HttpResult<?> flowJkPage(SpcyFlowVo spcyFlowVo, PageVo pageVo, OrderItemVo orderItemVo){
        /*if (StringUtils.isNotBlank(bjzt)){
            if (bjzt.equals("所有")){
                spcyFlowVo.setBjlc("是");
            }
            if (bjzt.equals("办结")) {
                spcyFlowVo.setFlczt(YpscFlowConstant.HJMC_LCJS);
            }
            if (bjzt.equals("撤件")){
                spcyFlowVo.setFlczt(PutZwxtConstant.SQSX_LCZT_QYCJ);
            }
            if (bjzt.equals("非中心事项")){
                spcyFlowVo.setFlczt(PutZwxtConstant.SQSX_LCZT_FZXBLSX);
            }
        }*/

        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        spcyFlowVo.setFlcmc(SpcyFlowConstant.LCMC_LIKE_SPCYLC);
        IPage<SpcyFlowVo> list = spcyFlowMapper.flowJkPage(page,false,null,spcyFlowVo,orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "待办事项-分页查询")
    @ApiOperation(value = "待办事项-分页查询")
    @GetMapping("flowJobPage")
    public HttpResult<?> flowJobPage(SpcyFlowVo spcyFlowVo, PageVo pageVo, OrderItemVo orderItemVo,
                                     @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser){
        CurrentUserVo user = GetCurrentUserUtils.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }

        // 验证是否为检查员身份
        /*if (user.getOrgId().equals(SpcyConstant.HCY_ORGID)){
            spcyFlowVo.setFhjmc(SpcyFlowConstant.HJMC_XCJC);
        }*/

        spcyFlowVo.setFblzt(SpcyConstant.BLZT_DB);

        spcyFlowVo.setFlcmc(SpcyFlowConstant.LCMC_LIKE_SPCYLC);

        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        IPage<SpcyFlowVo> list = spcyFlowMapper.flowJobPage(page,onlyCurrentUser,user,spcyFlowVo, orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "app-现场检查待办-分页查询")
    @ApiOperation(value = "app-现场检查待办-分页查询")
    @GetMapping("xcjcDbList")
    public HttpResult xcjcDbList(SpcyFlowVo spcyFlowVo, OrderItemVo orderItemVo){
        CurrentUserVo user = GetCurrentUserUtils.getCurrentUser();
        if (user == null){
            return HttpResult.error("身份过期，请重新登录！");
        }

        // 验证是否为检查员身份
        spcyFlowVo.setFhjmc(SpcyFlowConstant.HJMC_XCJC);
        spcyFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        spcyFlowVo.setFlcmc(SpcyFlowConstant.LCMC_LIKE_SPCYLC);

        Page<SpcyFlowVo> page = new Page<>(1, 20);

        IPage<SpcyFlowVo> list = spcyFlowMapper.flowJobPage(page,true, user, spcyFlowVo, orderItemVo);
        return HttpResultVo.HttpResultList(list.getRecords());
    }

    @Log(title = "待办事项-分页查询-任务登记")
    @ApiOperation(value = "待办事项-分页查询-任务登记")
    @GetMapping("flowJobRwdjPage")
    public HttpResult<?> flowJobRwdjPage(SpcyFlowVo spcyFlowVo, PageVo pageVo, OrderItemVo orderItemVo,
                                     @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser){
        CurrentUserVo user = GetCurrentUserUtils.getCurrentUser();
        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        spcyFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        spcyFlowVo.setFhjmc(SpcyFlowConstant.HJMC_RWSL);
//        spcyFlowVo.setFxzspzt(SpcyConstant.SQSX_BASIC_XZSPZT_RCJG);
//        spcyFlowVo.setFywflcode(SpcyConstant.getYwflByDeptName(user.getOrgName()));

        IPage<SpcyFlowVo> list = spcyFlowMapper.flowJobPage(page,onlyCurrentUser,user,spcyFlowVo, orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "待办事项-分页查询-日常检查")
    @ApiOperation(value = "待办事项-分页查询-日常检查")
    @GetMapping("flowJobRcjcPage")
    public HttpResult<?> flowJobRcjcPage(SpcyFlowVo spcyFlowVo, PageVo pageVo, OrderItemVo orderItemVo,
                                         @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser){
        CurrentUserVo user = GetCurrentUserUtils.getCurrentUser();
        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        spcyFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        spcyFlowVo.setFhjmc(SpcyFlowConstant.HJMC_RWSL);
//        spcyFlowVo.setFxzspzt(SpcyConstant.SQSX_BASIC_XZSPZT_RCJC);
//        spcyFlowVo.setFywflcode(SpcyConstant.getYwflByDeptName(user.getOrgName()));

        IPage<SpcyFlowVo> list = spcyFlowMapper.flowJobPage(page,onlyCurrentUser,user,spcyFlowVo, orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "预办理事项-分页查询")
    @ApiOperation(value = "预办理事项-分页查询")
    @GetMapping("flowPreparePage")
    public HttpResult<?> flowPreparePage(SpcyFlowVo spcyFlowVo, PageVo pageVo, OrderItemVo orderItemVo,
                                         @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser){
        CurrentUserVo user = GetCurrentUserUtils.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }

        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        spcyFlowVo.setFlcmc(SpcyFlowConstant.LCMC_LIKE_SPCYLC);

        // 是否查询-提前办
        if (StringUtils.isNotBlank(spcyFlowVo.getFlcsfkb()) && spcyFlowVo.getFlcsfkb().equals(SpcyFlowConstant.JOB_LCSFKB_TJB)){
            IPage<SpcyFlowVo> list = spcyFlowMapper.flowPreparePage(page,onlyCurrentUser,user,spcyFlowVo,orderItemVo);
            return HttpResult.ok(list);

        }else {

            if (StringUtils.isBlank(spcyFlowVo.getFblzt())){
                spcyFlowVo.setFblzt(SpcyConstant.BLZT_DB);
            }

            IPage<SpcyFlowVo> list = spcyFlowMapper.flowJobPage(page, onlyCurrentUser, user, spcyFlowVo, orderItemVo);
            return HttpResult.ok(list);
        }
    }

    @Log(title = "事项查询-分页查询")
    @ApiOperation(value = "事项查询-分页查询")
    @GetMapping("flowSqsxPage")
    public HttpResult<?> flowSqsxPage(SpcyFlowVo flowVo, PageVo pageVo, OrderItemVo orderItemVo){
        CurrentUserVo user = GetCurrentUserUtils.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }

        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        flowVo.setFlcmc(SpcyFlowConstant.LCMC_LIKE_SPCYLC);
        IPage<SpcyFlowVo> list = spcyFlowMapper.selectSqsxCxPage(page,null,flowVo,orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "我的已办事项查询-分页查询")
    @ApiOperation(value = "我的已办事项查询-分页查询")
    @GetMapping("querySqsxHandlingPage")
    public HttpResult<?> querySqsxHandlingPage(SpcyFlowVo flowVo, PageVo pageVo, OrderItemVo orderItemVo){
        String userid = GetCurrentUserUtils.getCurrentUserId();
        flowVo.setFblzt(SpcyConstant.BLZT_YB);

        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        flowVo.setFlcmc(SpcyFlowConstant.LCMC_LIKE_SPCYLC);
        IPage<SpcyFlowVo> list = spcyFlowMapper.selectJbSqsxPage(page, userid, flowVo, orderItemVo);

        /*if (CollectionUtil.isNotEmpty(list.getRecords())){
            list.setRecords(list.getRecords().stream().collect(Collectors.collectingAndThen(
                    Collectors.toCollection(
                            () -> new TreeSet<>(
                                    Comparator.comparing(o -> o.getSqsxid())
                            )
                    ), ArrayList<SpcyFlowVo>::new
            )));
            list.setTotal(list.getRecords().size());
        }*/
        return HttpResult.ok(list);
    }

    @Log(title = "我的主办事项查询-分页查询")
    @ApiOperation(value = "我的主办事项查询-分页查询")
    @GetMapping("queryZbSqsxPage")
    public HttpResult queryZbSqsxPage(SpcyFlowVo flowVo, PageVo pageVo, OrderItemVo orderItemVo){
        String userid = GetCurrentUserUtils.getCurrentUserId();
        flowVo.setFblzt(SpcyConstant.BLZT_YB);
        flowVo.setFzbr(userid);
        Page<SpcyFlowVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        flowVo.setFlcmc(SpcyFlowConstant.LCMC_LIKE_SPCYLC);
        IPage<SpcyFlowVo> list = spcyFlowMapper.selectZbSqsxPage(page, userid, flowVo, orderItemVo);
        return HttpResult.ok(list);
    }

    @Log(title = "查询流程任务详情-根据流程任务id")
    @ApiOperation(value = "查询流程任务详情-根据流程任务id")
    @GetMapping(value = "getJobConcernByJobId")
    public HttpResult getJobConcernByJobId(@RequestParam(value = "jobid",defaultValue = "")String jobid){
        if (StringUtils.isBlank(jobid)){
            return HttpResult.error("流程参数为空！");
        }
        return HttpResult.ok(spcyFlowService.getJobConcernByJobId(jobid,null));
    }

    @Log(title = "获取APP-审评查询流程任务详情")
    @ApiOperation(value = "获取APP-审评查询流程任务详情")
    @GetMapping(value = "getAppJobInfo")
    public HttpResult getAppJobInfo(@RequestParam(value = "jobid",defaultValue = "")String jobid){
        if (StringUtils.isBlank(jobid)){
            return HttpResult.error("流程参数为空！");
        }
        return HttpResult.ok(spcyFlowService.getAppJobConcernByJobId(jobid,null));
    }

    @Log(title = "查询申请事项-详情信息-通过申请事项id")
    @ApiOperation(value = "查询申请事项-详情信息-通过申请事项id")
    @GetMapping(value = "querySqsxDetailsById")
    public HttpResult querySqsxDetailsById(@RequestParam(value = "sqsxid",defaultValue = "0")String sqsxid){
        return HttpResult.ok(spcyFlowService.getJobConcernByJobId(null,sqsxid));
    }

    @Log(title = "将（不可办）流程任务转为（提前办）办理")
    @ApiOperation(value = "将（不可办）流程任务转为（提前办）办理")
    @PostMapping("updateKbJobInBkb")
    public HttpResult updateKbJobInBkb(@RequestBody JobAdvanceParamsBo paramsBo){
        spcyService.updateKbJobInBkb(paramsBo);

        return HttpResult.ok("办理成功");
    }

    @Log(title = "新增申请事项-任务登记")
    @ApiOperation(value = "新增申请事项-任务登记")
    @GetMapping(value = "addSqsxBasic")
    public HttpResult<?> addSqsxBasic(){
        // 接口限流
        if (!IpRateLimiterUtils.tryAcquire(GetCurrentUserUtils.getCurrentUserId())){
            return HttpResult.error("访问过于频繁，请稍候再试！");
        }

//        String fywflcode = SpcyConstant.getSqsxCodeByUser(GetCurrentUserUtils.getCurrentUserOrgName());
        String fywflcode = SpcyConstant.YWFL_CODE_YPSC;


        Map map = spcyService.addSqsxBasic(fywflcode, "");

        return HttpResult.ok(map);
    }

    @Log(title = "新增申请事项(日常检查-专项检查)")
    @ApiOperation(value = "新增申请事项(日常检查-专项检查)")
    @GetMapping(value = "addZxjcSqsx")
    public HttpResult<?> addZxjcSqsx(){
        // 接口限流
        if (!IpRateLimiterUtils.tryAcquire(GetCurrentUserUtils.getCurrentUserId())){
            return HttpResult.error("访问过于频繁，请稍候再试！");
        }

//        String fywflcode = SpcyConstant.getSqsxCodeByUser(GetCurrentUserUtils.getCurrentUserOrgName());
        String fywflcode = SpcyConstant.YWFL_CODE_YPSC;

        return spcyService.addZxjcSqsxBasic(fywflcode, null);
    }

    @Log(title = "删除任务登记事项-通过流程任务ids")
    @ApiOperation(value = "删除任务登记事项-通过流程任务ids")
    @DeleteMapping(value = "/delRwdjJob")
    public HttpResult<?> delRwdjJob(@RequestParam(value = "jobids",defaultValue = "")String jobids){
        if (StringUtils.isBlank(jobids)){
            return HttpResult.error("参数为空！");
        }

        spcyService.delRwdjJob(jobids);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "获取对应科室的经办人")
    @ApiOperation(value = "获取对应科室的经办人")
    @GetMapping(value = "getDeptJbrList")
    public HttpResult<?> getDeptJbrList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        Map deptJbrList = spcyFlowService.getDeptJbrList(sqsxid, null);

        return HttpResult.ok(deptJbrList);
    }

    @Log(title = "流程保存接口")
    @ApiOperation(value = "流程保存接口")
    @PostMapping(value = "/saveFlow")
    public HttpResult<?> saveFlow(@RequestBody FlowVo flowVo) {
        String submitType = SpcyFlowConstant.SUBMIT_TYPE_SAVE; // 保存

        if (StringUtils.isBlank(flowVo.getJobid())){
            return HttpResult.error("流程任务参数丢失，请联系管理员！");
        }

        // 流程处理
        Result httpResult = spcyFlowService.handleFlow(flowVo,  flowVo.getJobid(), submitType, flowVo.getOpinion());
        if (!httpResult.isSuccess()){
            return HttpResult.error(httpResult.getMessage());
        }

        return HttpResult.ok("保存成功");
    }

    @Log(title = "审评查验-流程提交接口")
    @ApiOperation(value = "审评查验-流程提交接口")
    @PostMapping(value = "/submitFlow")
    public HttpResult<?> submitFlow(@RequestBody FlowVo flowVo) {
        // 接口限流
        if (!IpRateLimiterUtils.tryAcquire(GetCurrentUserUtils.getCurrentUserId())){
            return HttpResult.error("访问过于频繁，请稍候再试！");
        }

        String submitType = SpcyFlowConstant.SUBMIT_TYPE_SUBMIT; // 提交
        if (StringUtils.isBlank(flowVo.getJobid())){
            return HttpResult.error("流程任务参数丢失，请联系管理员！");
        }

        SpcySqsxJob nowJob = spcySqsxJobMapper.selectById(flowVo.getJobid());
        if (nowJob == null){
            return HttpResult.error("当前流程任务不存在，请刷新重试！");
        }

        Result httpResult1 = spcyFlowService.handleFlow(flowVo, flowVo.getJobid(), nowJob, submitType, flowVo.getOpinion());
        if (!httpResult1.isSuccess()){
            return HttpResult.error(httpResult1.getMessage());
        }

        // 实时推送流转意见
        putZwxtService.pushSingletonSpJobLzjl(nowJob.getFpid());

        return HttpResult.ok("提交成功");
    }

    @Log(title = "退回政务-流程提交接口")
    @ApiOperation(value = "退回政务-流程提交接口")
    @PostMapping(value = "/submitFlowByZwfw")
    public HttpResult<?> submitFlowByZwfw(@RequestBody FlowVo flowVo) {
        // 接口限流
        if (!IpRateLimiterUtils.tryAcquire(GetCurrentUserUtils.getCurrentUserId())){
            return HttpResult.error("访问过于频繁，请稍候再试！");
        }

        String submitType = SpcyFlowConstant.SUBMIT_TYPE_SUBMIT; // 提交
        if (StringUtils.isBlank(flowVo.getJobid())){
            return HttpResult.error("流程任务参数丢失，请联系管理员！");
        }
        if (StringUtils.isBlank(flowVo.getOpinion())){
            return HttpResult.error("办理意见为空！");
        }

        SpcySqsxJob nowJob = spcySqsxJobMapper.selectById(flowVo.getJobid());
        if (nowJob == null){
            return HttpResult.error("当前流程任务不存在，请刷新重试！");
        }

        Result httpResult1 = spcyFlowService.handleThzwfwNodeName(flowVo, flowVo.getJobid(), nowJob, submitType, flowVo.getOpinion());
        if (!httpResult1.isSuccess()){
            return HttpResult.error(httpResult1.getMessage());
        }

        // 实时推送流转意见
        putZwxtService.pushSingletonSpJobLzjl(nowJob.getFpid());

        return HttpResult.ok("提交成功");
    }

    @Log(title = "批量提交流程")
    @ApiOperation(value = "批量提交流程")
    @PostMapping("batchSubmitRwsl")
    public HttpResult batchSubmitRwsl(@RequestBody BatchSubmitJobParamBo paramVo){
        spcyService.batchSubmitJob(paramVo);
        return HttpResult.ok("提交成功");
    }

    @Log(title = "单个科室内部转办")
    @ApiOperation(value = "单个科室内部转办")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(value = "jobid",name = "当前流程任务jobid"),
            @ApiImplicitParam(value = "ksfl",name = "转办科室分类(001002: 药品生产/001001: 药品注册/001003: 药品流通/002: 医疗器械/003: 化妆品)")
    })
    @PostMapping(value = "innerChangeFlowJob")
    public HttpResult<?> innerChangeFlowJob(@RequestBody Map<String,String> map){
        String jobid = map.get("jobid");
        String ksfl = map.get("ksfl");
        spcyFlowService.innerChangeFlowJob(jobid, ksfl);

        return HttpResult.ok("转办成功");
    }

    @Log(title = "流程转办")
    @ApiOperation(value = "流程转办")
    @PostMapping(value = "transferFlowJob")
    public HttpResult transferSpcyFlowJob(@RequestBody SpcyReturnVo spcyReturnVo){

        spcyFlowService.transferSpcyFlowJob(spcyReturnVo);
        return HttpResult.ok("转办成功");
    }

    @Log(title = "获取流程退回列表")
    @ApiOperation(value = "获取流程退回列表")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobid",value = "流程任务id")
    })
    @GetMapping(value = "queryAllYbJob")
    public HttpResult<?> queryAllYbJob(@RequestParam(value = "jobid",defaultValue = "")String jobid){

        List<Map<String, String>> currentJobPrevious = spcyService.getCurrentJobPrevious(jobid, false);
        return HttpResult.ok(currentJobPrevious);
    }

    @Log(title = "流程退回")
    @ApiOperation(value = "流程退回")
    @PostMapping(value = "returnUpperFlowJob")
    public HttpResult<?> returnUpperFlowJob(@RequestBody SpcyReturnVo spcyReturnVo){

        // 接口限流
        if (!IpRateLimiterUtils.tryAcquire(GetCurrentUserUtils.getCurrentUserId())){
            return HttpResult.error("访问过于频繁，请稍候再试！");
        }

        Result result = spcyFlowService.returnZdJob(spcyReturnVo);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }
        return HttpResult.ok("退回成功");
    }


    /***********************************************【 业务功能 】**********************************************************/

    @Log(title = "获取检查方案文件-PC")
    @ApiOperation(value = "获取检查方案文件-PC")
    @GetMapping(value = "getJcfaFile")
    public HttpResult getJcfaFile(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        List<SpcySqsxWjjl> lists = spcyService.queryJcfaFile(sqsxid);
        return HttpResult.ok(lists);
    }

    @Log(title = "验证是否已经存在检查方案 (0: 不存在，1：存在)")
    @ApiOperation(value = "验证是否已经存在检查方案 (0: 不存在，1：存在)")
    @GetMapping(value = "yzczJcfa")
    public HttpResult yzczJcfa(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        return spcyService.verifyExistsJcfaFile(sqsxid);
    }

    /*@Log(title = "获取检查方案文件-APP")
    @ApiOperation(value = "获取检查方案文件-APP")
    @GetMapping(value = "getJcfaApp")
    public HttpResult getJcfaApp(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        List<SpcySqsxWjjl> lists = spcyService.queryJcfaFile(sqsxid);
        return HttpResult.ok(lists);
    }

    @Log(title = "获取现场检查笔录文件-APP")
    @ApiOperation(value = "获取现场检查笔录文件-APP")
    @GetMapping(value = "getJcblApp")
    public HttpResult getJcblApp(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        List<SpcySqsxWjjl> lists = spcyService.queryWjjlByType(sqsxid, WjmlConstant.xcjcbl);
        return HttpResult.ok(lists);
    }*/

    @Log(title = "获取现场检查报告文件")
    @ApiOperation(value = "获取现场检查报告文件")
    @GetMapping(value = "getXcjcbgFile")
    public HttpResult getXcjcbgFile(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        return HttpResult.ok(spcyService.getXcjcbgFile(sqsxid));
    }

    @Log(title = "获取现场检查缺陷报告文件")
    @ApiOperation(value = "获取现场检查缺陷报告文件")
    @GetMapping(value = "getXcjcqxbgFile")
    public HttpResult getXcjcqxbgFile(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        return HttpResult.ok(spcyService.getXcjcqxbgFile(sqsxid));
    }

    @Log(title = "获取综合评定报告书文件")
    @ApiOperation(value = "获取综合评定报告书文件")
    @GetMapping(value = "getZhpdbgFile")
    public HttpResult getZhpdbgFile(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        return HttpResult.ok(spcyService.getZhpdbgFile(sqsxid));
    }

    @Log(title = "获取移送函文件")
    @ApiOperation(value = "获取移送函文件")
    @GetMapping(value = "getZhpdYshFile")
    public HttpResult getZhpdYshFile(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        return HttpResult.ok(spcyService.getZhpdYshFile(sqsxid));
    }

//    @Log(title = "获取检查通讯录功能")
//    @ApiOperation(value = "获取检查通讯录功能")
    @GetMapping(value = "getInspectAddressBook")
    public HttpResult getInspectAddressBook(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        List<List<String>> lists = spcyService.generateSqsxInspectAddressBook(sqsxid);
        return HttpResult.ok(lists);
    }

    @Log(title = "获取检查依据")
    @ApiOperation(value = "获取检查依据")
    @GetMapping(value = "getJcyj")
    public HttpResult getJcyj(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                              @RequestParam(value = "fmbnr",defaultValue = "")String fmbnr){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(sqsxid);
        if (sqsx == null){
            return HttpResult.error("没有相匹配的事项数据！");
        }
        List<Map> lists = ywlxmbService.queryJcyj(sqsx, sqsxid, fmbnr);

        Map resultMap = new HashMap();
        resultMap.put("records", lists);
        return HttpResult.ok(resultMap);
    }

    @Log(title = "获取检查情况专述模板")
    @ApiOperation(value = "获取检查情况专述模板")
    @GetMapping(value = "getJcqkzgMb")
    public HttpResult getJcqkzgMb(SpcySqsxYwlxmb ywlxmb, PageVo pageVo,
                                  @RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(sqsxid);
        ywlxmb.setFmblx(YwlxmbConstant.MBLX_JCQKZS);
        return ywlxmbService.queryPage(ywlxmb, sqsx, pageVo.getPageNo(), pageVo.getPageSize());
    }

    @Log(title = "保存申请事项信息")
    @ApiOperation(value = "保存申请事项信息")
    @PostMapping(value = "saveJbxx")
    public HttpResult saveJbxx(@RequestBody SqsxSaveVo paramVo){

        Result result = spcyService.updateSqsxBasic(paramVo.getMap(), paramVo.getSqsxid());
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("保存成功");
    }

    @Log(title = "获取检查报告模板")
    @ApiOperation(value = "获取检查报告模板")
    @GetMapping(value = "getJcbgMb")
    public HttpResult getJcbgMb(SpcySqsxYwlxmb ywlxmb, PageVo pageVo,
                                @RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(sqsxid);
        ywlxmb.setFmblx(YwlxmbConstant.MBLX_JCBG);
        return ywlxmbService.queryPage(ywlxmb, sqsx, pageVo.getPageNo(), pageVo.getPageSize());
    }

    @Log(title = "获取缺陷报告模板")
    @ApiOperation(value = "获取缺陷报告模板")
    @GetMapping(value = "getQxbgMb")
    public HttpResult getQxbgMb(SpcySqsxYwlxmb ywlxmb, PageVo pageVo,
                                @RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(sqsxid);
        ywlxmb.setFmblx(YwlxmbConstant.MBLX_QXBG);
        return ywlxmbService.queryPage(ywlxmb, sqsx, pageVo.getPageNo(), pageVo.getPageSize());
    }

    @Log(title = "选择事项业务字段相关模板")
    @ApiOperation(value = "选择事项业务字段相关模板")
    @GetMapping(value = "selectMb")
    public HttpResult selectMb(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("事项参数为空！");
        }
        String content = ywlxmbService.selectMb(id);

        Map resultMap = new HashMap();
        resultMap.put("fmbnr", content);
        return HttpResult.ok(resultMap);
    }


    @Log(title = "添加检查依据")
    @ApiOperation(value = "添加检查依据")
    @PostMapping(value = "addJcyj")
    public HttpResult addJcyj(@RequestBody JcyjParamBo paramBo){
        if (StringUtils.isBlank(paramBo.getSqsxid())){
            return HttpResult.error("事项参数为空！");
        }
        if (StringUtils.isBlank(paramBo.getFmbnr())){
            return HttpResult.error("内容为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(paramBo.getSqsxid());
        if (sqsx == null){
            return HttpResult.error("当前事项数据不存在！");
        }
        ywlxmbService.addJcyjMbByJcyj(paramBo.getFmbnr(),sqsx.getFywflcode(),paramBo.getSqsxid());

        return HttpResult.ok("保存成功");
    }

    @Log(title = "添加检查情况专述模板")
    @ApiOperation(value = "添加检查情况专述模板")
    @PostMapping(value = "addJcqkzsMb")
    public HttpResult addJcqkzsMb(@RequestBody JcyjParamBo paramBo){
        if (StringUtils.isBlank(paramBo.getSqsxid())){
            return HttpResult.error("事项参数为空！");
        }
        if (StringUtils.isBlank(paramBo.getFmbnr())){
            return HttpResult.error("内容为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(paramBo.getSqsxid());
        if (sqsx == null){
            return HttpResult.error("当前事项数据不存在！");
        }
        ywlxmbService.addJcyjMbByJcqkzs(paramBo.getFmbnr(),sqsx.getFywflcode(),paramBo.getSqsxid());

        return HttpResult.ok("保存成功");
    }

    @Log(title = "添加检查报告模板")
    @ApiOperation(value = "添加检查报告模板")
    @PostMapping(value = "addJcbgMb")
    public HttpResult addJcbgMb(@RequestBody JcyjParamBo paramBo){
        if (StringUtils.isBlank(paramBo.getSqsxid())){
            return HttpResult.error("事项参数为空！");
        }
        if (StringUtils.isBlank(paramBo.getFmbnr())){
            return HttpResult.error("内容为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(paramBo.getSqsxid());
        if (sqsx == null){
            return HttpResult.error("当前事项数据不存在！");
        }
        ywlxmbService.addJcyjMbByJcbg(paramBo.getFmbnr(),sqsx.getFywflcode(),paramBo.getSqsxid());

        return HttpResult.ok("保存成功");
    }

    @Log(title = "添加缺陷报告模板")
    @ApiOperation(value = "添加缺陷报告模板")
    @PostMapping(value = "addQxbgMb")
    public HttpResult addQxbgMb(@RequestBody JcyjParamBo paramBo){
        if (StringUtils.isBlank(paramBo.getSqsxid())){
            return HttpResult.error("事项参数为空！");
        }
        if (StringUtils.isBlank(paramBo.getFmbnr())){
            return HttpResult.error("内容为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(paramBo.getSqsxid());
        if (sqsx == null){
            return HttpResult.error("当前事项数据不存在！");
        }
        ywlxmbService.addJcyjMbByQxbg(paramBo.getFmbnr(),sqsx.getFywflcode(),paramBo.getSqsxid());

        return HttpResult.ok("保存成功");
    }

    @Log(title = "删除检查依据")
    @ApiOperation(value = "删除检查依据")
    @DeleteMapping(value = "deleteJcyj")
    public HttpResult deleteJcyj(@RequestParam(value = "id",defaultValue = "")String id){

        ywlxmbService.deleteYwlxmb(id);
        return HttpResult.ok("删除成功");
    }

    @Log(title = "下载申请事项-模板套用文件")
    @ApiOperation(value = "下载申请事项-模板套用文件")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id"),
            @ApiImplicitParam(name = "type",value = "模板类型"),
            @ApiImplicitParam(name = "id",value = "模板id"),
    })
    @GetMapping(value = "downloadSqsxFileMb")
    public void downloadSqsxFileMb(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                   @RequestParam(value = "type",defaultValue = "")String type,
                                   @RequestParam(value = "id",defaultValue = "")String wjmbId,
                                   HttpServletResponse response) throws IOException {

        initWjjlService.downloadSqsxFileMb(wjmbId, sqsxid, type, response);
    }

    @Log(title = "上传申请事项文件")
    @ApiOperation(value = "上传申请事项文件")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id"),
            @ApiImplicitParam(name = "type",value = "模板类型"),
            @ApiImplicitParam(name = "fwjxsmc",value = "自定义-文件显示名称(非必填)")
    })
    @PostMapping(value = "uploadSqsxFile")
    public HttpResult uploadSqsxFile(@RequestPart("file") MultipartFile[] uploadFile,
                                     @RequestParam(value = "sqsxid",defaultValue = "") String sqsxid,
                                     @RequestParam(value = "type",defaultValue = "") String type,
                                     @RequestParam(value = "fwjxsmc",defaultValue = "") String fwjxsmc){
        if (uploadFile == null || uploadFile.length == 0) {
            return HttpResult.error("上传失败,请先选择文件！");
        }

        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        if (StringUtils.isBlank(type)){
            return HttpResult.error("请选择要上传的文件类型！");
        }

        if (StringUtils.isNotBlank(fwjxsmc)){
            /*if (fwjxsmc.contains(".")){
                return HttpResult.error("文件名称不能带【.】！");
            }

            if (fwjxsmc.contains("/")){
                return HttpResult.error("文件名称不能带【/】！");
            }*/
            String validFileName = StringPatternUtils.isValidFileName(fwjxsmc);
            if (StringUtils.isNotBlank(validFileName)){
                return HttpResult.error("文件名不能存在特殊字符："+validFileName);
            }
        }

        initWjjlService.uploadSqsxFile(uploadFile, sqsxid, type, fwjxsmc,false);

        return HttpResult.ok("上传成功");
    }

    /***********************************************【 现场检查章节 】**********************************************************/

    @Log(title = "初始化现场检查章节")
    @ApiOperation(value = "初始化现场检查章节")
    @GetMapping(value = "initXcjczj")
    public HttpResult initXcjczj(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcySqsxBaiscMapper.selectSqsxById(sqsxid);
        spcyFlfgService.initXcjczj(sqsx, sqsxid);

        return HttpResult.ok("操作成功");
    }

    @Log(title = "初始化现场检查章节(文件模板章节)")
    @ApiOperation(value = "初始化现场检查章节(文件模板章节)")
    @GetMapping(value = "initWjmbZjGenXcjczj")
    public HttpResult initWjmbZjGenXcjczj(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcySqsxBaiscMapper.selectSqsxById(sqsxid);
        List<SpcyRsWjmbZjml> wjmbZjmlList = spcyRsWjmbZjmlService.selectWjmbZjmlList(sqsxid);
        spcyFlfgService.initWjmbZjGenXcjczj(wjmbZjmlList, sqsx, sqsxid);

        return HttpResult.ok("操作成功");
    }

    @Log(title = "获取现场检查分配任务章节列表")
    @ApiOperation(value = "获取现场检查分配任务章节列表")
    @GetMapping(value = "getXcjcFprwZjList")
    public HttpResult getXcjcFprwZjList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        return HttpResultVo.HttpResultList(spcyFlfgService.queryXcjcZjBySqsxId(sqsxid));
    }

    @Log(title = "获取用户负责的现场检查章节")
    @ApiOperation(value = "获取用户负责的现场检查章节")
    @GetMapping(value = "queryXcjczjByNowUser")
    public HttpResult queryXcjczjByNowUser(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

//        boolean isZz = true;
        /** 验证是否为合并事项 */
        /*if (spcyHbjcService.verifyBhbSqsxIsHbsqsx(sqsxid, null)){
            isZz = true;
        }else {*/
        /** 验证是否为组长 */
//        isZz = spcyService.verifyNowUserIsXpryZz(sqsxid);

        return HttpResult.ok(spcyFlfgService.queryXcjczjByNowUser(sqsxid, true));
    }

    @Log(title = "获取用户人员情况描述检查章节")
    @ApiOperation(value = "获取用户人员情况描述检查章节")
    @GetMapping(value = "queryRyqkmsZjList")
    public HttpResult queryRyqkmsZjList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        boolean isZz = spcyService.verifyNowUserIsXpryZz(sqsxid);
        return HttpResult.ok(spcyFlfgService.getRyqkmsZjList(sqsxid, isZz));
    }

    @Log(title = "更新用户人员情况描述检查章节")
    @ApiOperation(value = "更新用户人员情况描述检查章节")
    @PostMapping(value = "updateRyqkmsZjNr")
    public HttpResult updateRyqkmsZjNr(@RequestBody SpcyFgXcjczj paramVo){

        Result result = spcyFlfgService.updateRyqkmsZjContent(paramVo);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    /*@Log(title = "获取条款分页列表-根据检查章节id")
    @ApiOperation(value = "获取条款分页列表-根据检查章节id")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "fxcjczjid",value = "现场检查章节id"),
            @ApiImplicitParam(name = "gjz",value = "关键字")
    })*/
    @GetMapping("queryPageTkListByZjId")
    public HttpResult queryPageTkListByZjId(@RequestParam(value = "fxcjczjid",defaultValue = "")String fxcjczjid,
                                            @RequestParam(value = "gjz",defaultValue = "")String gjz,
                                            PageVo pageVo){

        return spcyFlfgService.queryPageXcjcTkListByXcjcZjId(fxcjczjid,gjz,pageVo.getPageNo(),pageVo.getPageSize());
    }

    /*@Log(title = "获取历史条款分页列表-根据检查章节id")
    @ApiOperation(value = "获取历史条款分页列表-根据检查章节id")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "fxcjczjid",value = "现场检查章节id"),
            @ApiImplicitParam(name = "gjz",value = "关键字")
    })*/
    @GetMapping("queryPageXcjcHistoryTkListByXcjcZjId")
    public HttpResult queryPageXcjcHistoryTkListByXcjcZjId(@RequestParam(value = "fxcjczjid",defaultValue = "")String fxcjczjid,
                                                           @RequestParam(value = "gjz",defaultValue = "")String gjz,
                                                           PageVo pageVo){

        return spcyFlfgService.queryPageXcjcHistoryTkListByXcjcZjId(fxcjczjid,gjz,pageVo.getPageNo(),pageVo.getPageSize());
    }

    @Log(title = "获取现场检查章节任务分配人员列表")
    @ApiOperation(value = "获取现场检查章节任务分配人员列表")
    @GetMapping(value = "getXcjcRwfpPersonList")
    public HttpResult getXcjcRwfpPersonList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        List<Map> list = spcyService.getXcjcRwfpPersonListNew(sqsxid);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "获取任务分配人员-对应的分配章节列表")
    @ApiOperation(value = "获取任务分配人员-对应的分配章节列表")
    @GetMapping(value = "getRwfpRyZjList")
    public HttpResult getRwfpRyZjList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                      @RequestParam(value = "userid",defaultValue = "")String userid){

        List<Map> list = spcyService.getRwfpRyZjList(sqsxid, userid);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "获取现场检查章节任务分配-添加")
    @ApiOperation(value = "获取现场检查章节任务分配-添加")
    @GetMapping(value = "getXcjcRwfpPersonAdd")
    public HttpResult getXcjcRwfpPersonAdd(@RequestParam(value = "id",defaultValue = "")String id,
                                           @RequestParam(value = "userid",defaultValue = "")String userid){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }

        if (StringUtils.isBlank(userid)){
            return HttpResult.error("人员为空！");
        }

        if (!id.contains("@")) {
            spcyFlfgService.getXcjcRwfpPersonAdd(id, userid);

        }else {
            LambdaUpdateWrapper<SpcyRsWjmbZjml> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(SpcyRsWjmbZjml::getId, id.split("@")[1]);

            SpcyRsWjmbZjml updateBean = new SpcyRsWjmbZjml();
            updateBean.setFtxfzrid(userid);

            spcyRsWjmbZjmlService.update(updateBean, updateWrapper);
        }

        return HttpResult.ok("添加成功");
    }

    @Log(title = "获取现场检查章节任务分配-移除")
    @ApiOperation(value = "获取现场检查章节任务分配-移除")
    @GetMapping(value = "getXcjcRwfpPersonRemove")
    public HttpResult getXcjcRwfpPersonRemove(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }

        if (!id.contains("@")) {
            spcyFlfgService.getXcjcRwfpPersonRemove(id);

        }else {
            LambdaUpdateWrapper<SpcyRsWjmbZjml> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(SpcyRsWjmbZjml::getId, id.split("@")[1]);

            SpcyRsWjmbZjml updateBean = new SpcyRsWjmbZjml();
            updateBean.setFtxfzrid("");

            spcyRsWjmbZjmlService.update(updateBean, updateWrapper);
        }

        return HttpResult.ok("移除成功");
    }

    @Log(title = "修改现场检查章节负责人")
    /*@ApiOperation(value = "修改现场检查章节负责人")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "fxcjczjid",value = "现场检查章节id"),
            @ApiImplicitParam(name = "userid",value = "选择的人员id")
    })*/
    @GetMapping(value = "modifyXcjcZjInFzr")
    public HttpResult modifyXcjcZjInFzr(@RequestParam(value = "fxcjczjid",defaultValue = "")String fxcjczjid,
                                        @RequestParam(value = "userid",defaultValue = "")String userid){

        Result result = spcyFlfgService.modifyXcjcZjInFzr(fxcjczjid, userid);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }
        return HttpResult.ok("保存成功");
    }

    @Log(title = "确定现场检查任务分配状态")
//    @ApiOperation(value = "确定现场检查任务分配状态")
    @GetMapping(value = "submitXcjcRyfp")
    public HttpResult submitXcjcRyfp(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        /*String fgid = null;
        SpcySqsxBasic sqsx = null;
        if (StringUtils.isBlank(fgid)) {
            sqsx = spcyService.querySqsxInfoById(sqsxid);
        }
        spcyFlfgService.verifyXcjczjRwfp(sqsxid,sqsx,fgid);  // 章节负责人-是否已经全部分配*/
        spcyService.updateXcjcRwfpState(sqsxid);

        return HttpResult.ok("确认成功");
    }


    @Log(title = "更新现场检查章节")
//    @ApiOperation(value = "更新现场检查章节")
    @PutMapping(value = "updatwXcjczj")
    public HttpResult updatwXcjczj(@RequestBody HashMap<String,Object> map){

        spcyFlfgService.updatwXcjczj(map);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "查询现场检查发现问题和条款")
    /*@ApiOperation(value = "查询现场检查发现问题和条款")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id"),
            @ApiImplicitParam(name = "ffxryid",value = "发现人员id")
    })*/
    @GetMapping(value = "queryListXcjcwtBySqsxId")
    public HttpResult queryListXcjcwtBySqsxId(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                              @RequestParam(value = "ffxryid",defaultValue = "")String ffxryid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        return HttpResultVo.HttpResultList(spcyFlfgService.queryListXcjcwtBySqsxId(sqsxid, ffxryid));
    }

    /*@Log(title = "选择历史发现问题")
    @ApiOperation(value = "选择历史发现问题")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id"),
            @ApiImplicitParam(name = "fxcjczjid",value = "现场检查章节id"),
            @ApiImplicitParam(name = "id",value = "历史发现问题条款id")
    })*/
    @GetMapping(value = "selectHistoryXcjcwt")
    public HttpResult selectHistoryXcjcwt(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                          @RequestParam(value = "fxcjczjid",defaultValue = "")String fxcjczjid,
                                          @RequestParam(value = "id",defaultValue = "")String lswttkid){

        spcyFlfgService.selectHistoryXcjcwt(lswttkid,fxcjczjid,sqsxid);
        return HttpResult.ok("添加成功");
    }

    @Log(title = "获取现场检查发现人员列表")
    @ApiOperation(value = "获取现场检查发现人员列表")
    @GetMapping(value = "fxryList")
    public HttpResult queryXcjcfxryList(@RequestParam(value = "sqsxid",defaultValue = "") @ApiParam("申请事项id") String sqsxid){

        return HttpResult.ok(spcyService.getXcjcFxryList(sqsxid));
    }

    @Log(title = "添加现场检查问题")
    @ApiOperation(value = "添加现场检查问题")
    @GetMapping(value = "addXcjcWt")
    public HttpResult addXcjcWt(@RequestParam(value = "sqsxid",defaultValue = "") @ApiParam("申请事项id") String sqsxid,
                                @RequestParam(value = "ffxryid",defaultValue = "") @ApiParam("发现人员id") String ffxryid){

        Result result = spcyFlfgService.addXcjcWt(sqsxid, ffxryid);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }
        return HttpResult.ok("添加成功");
    }

    @Log(title = "添加发现问题及条款")
    @ApiOperation(value = "添加发现问题及条款")
    @PostMapping(value = "addWtJtk")
    public HttpResult addWtJtk(@RequestBody FgWtVo fgWtVo){
        if (StringUtils.isBlank(fgWtVo.getSqsxid())){
            return HttpResult.error("事项参数为空！");
        }
        if (fgWtVo.getSubmitState() == null){
            return HttpResult.error("提交参数为空！");
        }

        if (fgWtVo.getSubmitState() == 1){
            if (StringUtils.isBlank(fgWtVo.getFwtms())){
                return HttpResult.error("请填写缺陷描述！");
            }
            if (StringUtils.isBlank(fgWtVo.getFyzcd())){
                return HttpResult.error("请选择缺陷类型！");
            }
            if (StringUtils.isBlank(fgWtVo.getFfxryid())){
                return HttpResult.error("请选择发现人员！");
            }
            if (StringUtils.isBlank(fgWtVo.getFxcjczjid())){
                return HttpResult.error("请选择报告章节！");
            }

            if (CollectionUtil.isEmpty(fgWtVo.getTkList())){
                return HttpResult.error("请填写依据！");
            }
        }

        return spcyFlfgService.addXcjcwtAndTk(fgWtVo);
    }

    @Log(title = "更新现场检查发现问题")
    @ApiOperation(value = "更新现场检查发现问题")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "问题id"),
            @ApiImplicitParam(name = "fwtms",value = "问题描述"),
            @ApiImplicitParam(name = "fyzcd",value = "严重程度(一般缺陷/主要缺陷/严重缺陷)"),
            @ApiImplicitParam(name = "ffxryid",value = "发现人员id"),
            @ApiImplicitParam(name = "fxcjczjid",value = "现场检查章节id"),
            @ApiImplicitParam(name = "fxcjczjmc",value = "现场检查章节名称(非Update)"),
            @ApiImplicitParam(name = "fwtzt",value = "完成状态(未完成/已完成)")
    })
    @PutMapping(value = "updatwXcjcwt")
    public HttpResult updatwXcjcwt(@RequestBody HashMap<String,Object> map){

        spcyFlfgService.updatwXcjcwt(map);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "删除现场检查发现问题")
    @ApiOperation(value = "删除现场检查发现问题")
    @DeleteMapping(value = "deleteXcjcwt")
    public HttpResult deleteXcjcwt(@RequestParam(value = "id",defaultValue = "") @ApiParam("问题id") String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }

        Result result = spcyFlfgService.deleteXcjcwt(id);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("删除成功");
    }

    @Log(title = "勾选添加发现问题条款")
    @ApiOperation(value = "勾选添加发现问题条款")
    @GetMapping(value = "addXcjcwttk")
    public HttpResult addXcjcwttk(@RequestParam(value = "fxcjcwtid",defaultValue = "") @ApiParam("问题id") String fxcjcwtid,
                                  @RequestParam(value = "ftkid",defaultValue = "") @ApiParam("条款id") String ftkid){

        Result result = spcyFlfgService.addXcjcwttk("", fxcjcwtid, ftkid, null, true);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }
        return HttpResult.ok("添加成功");
    }

    @Log(title = "手动添加问题条款")
    @ApiOperation(value = "手动添加问题条款")
    @PostMapping(value = "sdWttk")
    public HttpResult sdWttk(@RequestBody HandXcjcwtTkVo paramVo){

        Result result = spcyFlfgService.handAddXcjcWttk(paramVo);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("添加成功");
    }

    @Log(title = "修改问题条款")
    @ApiOperation(value = "修改问题条款")
    @PostMapping(value = "xgWttk")
    public HttpResult xgWttk(@RequestBody HandXcjcwtTkVo paramVo){

        Result result = spcyFlfgService.updateHandXcjcWttk(paramVo);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("保存成功");
    }

//    @Log(title = "重新选择发现问题条款")
//    @ApiOperation(value = "重新选择发现问题条款")
    @GetMapping(value = "againXcjcwttk")
    public HttpResult againXcjcwttk(@RequestParam(value = "id",defaultValue = "")String id,
                                    @RequestParam(value = "ftkid",defaultValue = "")String ftkid){

        Result result = spcyFlfgService.againXcjcwttk(id, ftkid, null, true);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }
        return HttpResult.ok("保存成功");
    }

    @Log(title = "删除发现问题条款")
    @ApiOperation(value = "删除发现问题条款")
    @DeleteMapping(value = "deleteXcjcwttk")
    public HttpResult deleteXcjcwttk(@RequestParam(value = "id",defaultValue = "") @ApiParam("问题条款id") String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }
        spcyFlfgService.deleteXcjcwttk(id);
        return HttpResult.ok("删除成功");
    }

    @Log(title = "获取现场检查章节描述模板")
    @ApiOperation(value = "获取现场检查章节描述模板")
    @GetMapping(value = "getXcjczjMsmbList")
    public HttpResult getXcjczjMsmbList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                        @RequestParam(value = "fxcjczjid",defaultValue = "")String fxcjczjid,
                                        @RequestParam(value = "fmbly",defaultValue = "")String fmbly,
                                        @RequestParam(value = "fmbnr",defaultValue = "")String fmbnr,
                                        PageVo pageVo){
        if (StringUtils.isBlank(fmbly)){
            fmbly = "我写过的描述";
        }
        Page<Map> page = new Page<>(pageVo.getPageNo(),pageVo.getPageSize());

        if (fmbly.equals("我写过的描述")){
            return spcyFlfgService.getAllHistoryMsmbList(page,fmbnr,null, fxcjczjid,true,false);
        }
        else if (fmbly.equals("其他检查员写过的")){
            return spcyFlfgService.getAllHistoryMsmbList(page,fmbnr,null, fxcjczjid,false,true);
        }
        else if (fmbly.equals("该企业的描述")){
            if (StringUtils.isBlank(sqsxid)){
                return HttpResult.error("申请事项参数为空！");
            }
            SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(sqsxid);
            return spcyFlfgService.getQyHistoryMsmbList(page,sqsx, sqsxid, fxcjczjid, fmbnr);
        }
        else if (fmbly.equals("所有历史描述")){
            return spcyFlfgService.getAllHistoryMsmbList(page,fmbnr,null, fxcjczjid,false,false);
        }else {
            return spcyFlfgService.getAllHistoryMsmbList(page,fmbnr, null, fxcjczjid,true,false);
        }
    }

    @Log(title = "选择现场检查章节描述模板")
    @ApiOperation(value = "选择现场检查章节描述模板")
    @GetMapping(value = "selectHistoryMsmb")
    public HttpResult selectHistoryMsmb(@RequestParam(value = "id",defaultValue = "")String id){
        spcyFlfgService.selectHistoryMsmb(id);

        return HttpResult.ok("调用成功");
    }

    @Log(title = "生成现场检查结论")
    @ApiOperation(value = "生成现场检查结论")
    @GetMapping(value = "generateXcjcConclusion")
    public HttpResult generateXcjcConclusion(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxInfoById(sqsxid);
        SqsxXcjcQxParamBo conclusion = spcyFlfgService.generateXcjcConclusion(sqsx, sqsxid);
        spcyService.updateSqsxXcjcQxxx(sqsxid, conclusion);

        Map resultMap = new HashMap();
        resultMap.put("conclusion", conclusion.getJl());
        resultMap.put("fjcqxxm", conclusion.getFjcqxxm());
        return HttpResult.ok(resultMap);
    }

    @Log(title = "生成综合评定结论")
    @ApiOperation(value = "生成综合评定结论")
    @GetMapping(value = "generateZhpdConclusion")
    public HttpResult generateZhpdConclusion(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxById(sqsxid);
        Map<String, String> conclusion = spcyFlfgService.generateZhpdConclusion(sqsx);

        return HttpResult.ok(conclusion);
    }

    @Log(title = "生成综合评定审查意见")
    @ApiOperation(value = "生成综合评定审查意见")
    @GetMapping(value = "genZhpdScyj")
    public HttpResult genZhpdScyj(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcyService.querySqsxById(sqsxid);
        if (sqsx == null){
            return HttpResult.error("没有相匹配的事项！");
        }

        String scyj = "";

        if (sqsx.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPSC)){
            scyj = spcyFlfgService.generateZhpdOpinion(sqsx, sqsxid);

        }
        else if (sqsx.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPZC)){
            scyj = spcyFlfgService.generateZhpdOpinion(sqsx, sqsxid);

        }
        else if (sqsx.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPJY)){
            scyj = spcyFlfgService.generateZhpdOpinion(sqsx, sqsxid);

        }
        else if (sqsx.getFywflcode().equals(SpcyConstant.YWFL_CODE_YLQX)){
            scyj = spcyFlfgService.generateZhpdOpinion(sqsx, sqsxid);

        }else if (sqsx.getFywflcode().equals(SpcyConstant.YWFL_CODE_HZP)){
            scyj = spcyFlfgService.generateZhpdOpinion(sqsx, sqsxid);

        }


        return HttpResultVo.HttpResultGet(scyj);
    }

    @Log(title = "生成整改通知内容")
    @ApiOperation(value = "生成整改通知内容")
    @GetMapping(value = "genZgtznr")
    public HttpResult genZgtznr(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        return HttpResultVo.HttpResultGet(spcyService.getZgtznr(sqsxid));
    }

    /***********************************************【 企业文件材料 】**********************************************************/

    @Log(title = "获取企业申请材料文件目录")
    @ApiOperation(value = "获取企业申请材料文件目录")
    @GetMapping(value = "queryQyWjclml")
    public HttpResult queryQyWjclml(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

//        boolean isReadable = spcyService.verifyQywjclAndMlReadableState(sqsxid);
        List<Map> mapList = sqsxQywjclService.queryQyWjclml(sqsxid, false);
        return HttpResult.ok(mapList);

    }

    @Log(title = "获取企业补齐补正文件目录")
    @ApiOperation(value = "获取企业补齐补正文件目录")
    @GetMapping(value = "queryQyBqbzWjclml")
    public HttpResult queryQyBqbzWjclml(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        List<Map> mapList = sqsxQywjclService.queryQyWjclml(sqsxid, false, true);
        return HttpResult.ok(mapList);
    }

    @Log(title = "获取PC-检查参考材料列表")
    @ApiOperation(value = "获取PC-检查参考材料列表")
    @GetMapping(value = "queryKckWjclList")
    public HttpResult queryKckWjclList(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        /** 查询任务受理是否存在待办 */
        List<String> list = spcySqsxJobMapper.selectIdByFhjmc(sqsxid, SpcyFlowConstant.HJMC_RWSL);
        if (CollectionUtil.isNotEmpty(list)){

            /** 存在任务受理查询所有文件 */
            return HttpResult.ok(sqsxQywjclService.queryAdlQySqWjclList(sqsxid));
        }else {

            return HttpResult.ok(sqsxQywjclService.queryKckWjclList(sqsxid));
        }
    }

    @Log(title = "获取APP-检查参考材料列表")
    @ApiOperation(value = "获取APP-检查参考材料列表")
    @GetMapping(value = "appJcckclList")
    public HttpResult appJcckclList(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)) {
            return HttpResult.error("事项参数为空！");
        }

        Map dataMap = new HashMap();
        dataMap.put("clmc", "检查参考材料");
        dataMap.put("wjList", sqsxQywjclService.queryKckWjclList(sqsxid));
        return HttpResult.ok(dataMap);
    }

    @ApiOperation(value = "预览企业申请材料")
    @ApiImplicitParam(name = "id",value = "文件id")
    @GetMapping(value = "downloadQysqclFile")
    public void downloadQysqclFile(@RequestParam(value = "id",defaultValue = "")String id, HttpServletResponse response) throws IOException {
        sqsxQywjclService.downloadQysqclFile(id, false, response);
    }

    @Log(title = "下载企业申请材料")
    @ApiOperation(value = "下载企业申请材料")
    @ApiImplicitParam(name = "id",value = "文件id")
    @GetMapping(value = "downloadQysqclById")
    public void downloadQysqclById(@RequestParam(value = "id",defaultValue = "")String id,
                                   @RequestParam(value = "isAddSy",defaultValue = "true")boolean isAddSy,
                                   HttpServletResponse response) throws IOException {
        sqsxQywjclService.downloadQysqclFile(id, isAddSy, response);
    }

    @Log(title = "更新目录")
    @ApiOperation(value = "更新目录")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "目录id"),
            @ApiImplicitParam(name = "fscyj",value = "审查意见"),
            @ApiImplicitParam(name = "fbcscyj",value = "补充审查意见"),
            @ApiImplicitParam(name = "fywscyj",value = "有无审查意见(有意见/无意见)"),
            @ApiImplicitParam(name = "fywbcscyj",value = "有无补充审查意见(有意见/无意见)")
    })
    @PutMapping(value = "updateMl")
    public HttpResult updateMl(@RequestBody HashMap<String,Object> map){
        sqsxQywjclService.updateMl(map);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "获取汇总材料目录-审查意见")
    @ApiOperation(value = "获取汇总材料目录-审查意见")
    @GetMapping(value = "getSummaryOpinionInScyj")
    public HttpResult getSummaryOpinionInScyj(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        HttpResult result = new HttpResult(true);
        result.setResult(spcyService.getSummaryOpinionInScyj(sqsxid));
        result.setMessage("操作成功");
        return result;
    }

    /** 2024-02-24 新增 */
    @ApiOperation(value = "验证是否存在审查意见(true: 存在/false: 不存在)")
    @GetMapping(value = "verifyQywjSfczScyj")
    public HttpResult verifyQywjSfczScyj(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        return HttpResult.ok(spcyService.verifyQywjSfczScyj(sqsxid));
    }

    @Log(title = "上传企业文件材料-中心")
    @ApiOperation(value = "上传企业文件材料-中心")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "file",value = "文件不能为空",required = true),
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
    })
    @PostMapping(value = "uploadQywjcl")
    public HttpResult uploadQywjcl(@RequestPart("file") MultipartFile[] uploadFile,
                                  @RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        sqsxQywjclService.uploadFile(uploadFile, sqsxid, false);

        return HttpResult.ok("上传成功");
    }

    @Log(title = "上传企业文件材料-企业")
    @ApiOperation(value = "上传企业文件材料-企业")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "file",value = "文件不能为空",required = true),
            @ApiImplicitParam(name = "sqsxid",value = "申请事项id",required = true),
            @ApiImplicitParam(name = "mlid",value = "企业材料目录id",required = true)
    })
    @PostMapping(value = "uploadQywjclByQy")
    public HttpResult uploadQywjclByQy(@RequestPart("file") MultipartFile[] uploadFile,
                                       @RequestParam(value = "sqsxid",defaultValue = "") String sqsxid,
                                       @RequestParam(value = "mlid",defaultValue = "") String mlid){
        if (StringUtils.isBlank(mlid)){
            return HttpResult.error("目录参数为空！");
        }
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        sqsxQywjclService.uploadQywjclByQy(uploadFile, sqsxid, mlid, true);

        return HttpResult.ok("上传成功");
    }

    @Log(title = "选择文件材料-现场检查文件可查看")
    @ApiOperation(value = "选择文件材料-现场检查文件可查看")
    @PostMapping(value = "selectWjclKck")
    public HttpResult selectWjclKck(@RequestBody ParamsBo paramsBo){

        Result result = sqsxQywjclService.selectWjclKck(paramsBo.getIds());
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "合并事项-选择企业材料-现场检查可查看材料")
    @ApiOperation(value = "合并事项-选择企业材料-现场检查可查看材料")
    @PostMapping(value = "selectHbkckcl")
    public HttpResult selectHbkckcl(@RequestBody HbSelectQyWjVo paramsBo){

        Result result = sqsxQywjclService.selectHbkckcl(paramsBo.getIds(), paramsBo.getSqsxid());
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "取消文件材料-现场检查可查看状态")
    @ApiOperation(value = "取消文件材料-现场检查可查看状态")
    @GetMapping(value = "cancelSelectWjclKck")
    public HttpResult cancelSelectWjclKck(@RequestParam(value = "id",defaultValue = "") String id){

        Result result = sqsxQywjclService.cancelSelectWjclKck(id);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "删除中心上传企业材料")
    @ApiOperation(value = "删除中心上传企业材料")
    @DeleteMapping(value = "deleteZxscQywjcl")
    public HttpResult deleteZxscQywjcl(@RequestParam(value = "id",defaultValue = "") String id){

        Result result = sqsxQywjclService.deleteQywjclById(id, true);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }
        return HttpResult.ok("删除成功");
    }

    @Log(title = "删除企业上传企业材料")
    @ApiOperation(value = "删除企业上传企业材料")
    @DeleteMapping(value = "deleteQyscQywjcl")
    public HttpResult deleteQyscQywjcl(@RequestParam(value = "id",defaultValue = "") String id){

        Result result = sqsxQywjclService.deleteQywjclById(id, false);
        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }

        return HttpResult.ok("删除成功");
    }

    @Log(title = "一键设置有审查意见")
    @ApiOperation(value = "一键设置有审查意见")
    @GetMapping(value = "oneTouchYesScyj")
    public HttpResult oneTouchYesScyj(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){

        sqsxQywjclService.updateYwScyj(sqsxid, true);
        return HttpResult.ok("操作成功");
    }

    @Log(title = "一键设置无审查意见")
    @ApiOperation(value = "一键设置无审查意见")
    @GetMapping(value = "oneTouchNoScyj")
    public HttpResult oneTouchNoScyj(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        sqsxQywjclService.updateYwScyj(sqsxid, false);
        return HttpResult.ok("操作成功");
    }

    @Log(title = "打包下载zip-企业提交材料")
    @ApiOperation(value = "打包下载zip-企业提交材料")
    @GetMapping(value = "downloadZipInQytjcl")
    public void downloadZipInQytjcl(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid, HttpServletResponse response){
        sqsxQywjclService.downloadZipInQytjcl(sqsxid, response);
    }

    /***********************************************【 其他 】**********************************************************/

    @Log(title = "获取办理过程材料-文件目录")
    @ApiOperation(value = "获取办理过程材料-文件目录")
    @GetMapping(value = "queryBlgcclMlList")
    public HttpResult queryBlgcclMlList(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        List<Map> mapList = spcyBlgcclService.queryBlgcclMlList(sqsxid);
        return HttpResult.ok(mapList);
    }

    @Log(title = "获取现场检查文件目录 (现场检查材料)")
    @ApiOperation(value = "获取现场检查文件目录 (现场检查材料)")
    @GetMapping(value = "queryXcjcFileMl")
    public HttpResult queryXcjcFileMl(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("操作失败！申请事项参数为空！");
        }

        List<Map> mapList = spcyBlgcclService.queryXcjcFileMl(sqsxid, WjmlConstant.wjml_type_1_xcjccl,false);
        return HttpResult.ok(mapList);
    }

    @Log(title = "获取首次会议-检查相关文件目录(办理材料)")
    @ApiOperation(value = "获取首次会议-检查相关文件目录(办理材料)")
    @GetMapping(value = "queryWjMlBySchyJc")
    public HttpResult queryWjMlBySchyJc(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        List<String> typeList = CollectionUtil.newArrayList(
                WjmlConstant.xcjchyqdb,
                WjmlConstant.xcjcjl,
                WjmlConstant.wlyctsm,
                WjmlConstant.xcjcjcycns
                );

        return HttpResult.ok(spcyBlgcclService.selectGroupWjjlByFtype(sqsxid, typeList));
    }

    @Log(title = "获取现场检查-现场检查笔录(办理材料)")
    @ApiOperation(value = "获取现场检查-现场检查笔录(办理材料)")
    @GetMapping(value = "queryWjmlByXcjcbl")
    public HttpResult queryWjmlByXcjcbl(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        List<String> typeList = CollectionUtil.newArrayList(
                WjmlConstant.xcjcbl
        );

        /** 组长查看所有附件，组员只看自己的附件 */
        if (spcyService.verifyNowUserIsXpryZz(sqsxid)) {
            return HttpResult.ok(spcyBlgcclService.selectGroupWjjlByFtype(sqsxid, typeList, false));

        }else {
            return HttpResult.ok(spcyBlgcclService.selectGroupWjjlByFtype(sqsxid, typeList, true));
        }
    }

    /*@Log(title = "检查员报销-获取对应选派函附件列表")
    @ApiOperation(value = "检查员报销-获取对应选派函附件列表")*/
    @GetMapping(value = "queryBxxpFile")
    public HttpResult queryBxxpFile(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        List<String> typeList = CollectionUtil.newArrayList(
                WjmlConstant.xpxcscydh
        );

        return HttpResult.ok(spcyBlgcclService.selectGroupWjjlByFtype(sqsxid, typeList, false));
    }

    @Log(title = "获取首次会议-现场检查移送企业材料目录(办理材料)")
    @ApiOperation(value = "获取首次会议-现场检查移送企业材料目录(办理材料)")
    @GetMapping(value = "queryWjMlBySchyQy")
    public HttpResult queryWjMlBySchyQy(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        return spcyBlgcclService.selectWjMlBySchyQy(sqsxid);
    }

    @Log(title = "打包下载zip-现场检查移送企业所有材料")
    @ApiOperation(value = "打包下载zip-现场检查移送企业所有材料(办理材料)")
    @GetMapping(value = "downZipZxclQy")
    public void downZipZxclQy(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid, HttpServletResponse response) throws IOException {
        if (StringUtils.isBlank(sqsxid)) {
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            PrintWriter writer = response.getWriter();
            writer.println("参数为空！");
            writer.close(); // 不要忘记关闭PrintWriter

            return;
        }

        List<String> typeList = CollectionUtil.newArrayList(
                WjmlConstant.qydwjctz,
                WjmlConstant.jczgclyq,
                WjmlConstant.xcjcjl,
                WjmlConstant.ljzlfk_cj,
                WjmlConstant.ljzlfk_fcj,
                WjmlConstant.cjcygzlfzdcb
        );
        spcyBlgcclService.downZipZxclQy(sqsxid, typeList, response);
    }

    @Log(title = "勾选打包下载zip-现场检查移送企业材料")
    @ApiOperation(value = "勾选打包下载zip-现场检查移送企业材料")
    @PostMapping(value = "gxZipYsQyCl")
    public void gxZipYsQyCl(@RequestBody XcjcQyFileZipVo paramVo,
                            HttpServletResponse response) throws IOException {
        if (StringUtils.isBlank(paramVo.getSqsxid())) {
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            PrintWriter writer = response.getWriter();
            writer.println("参数为空！");
            writer.close(); // 不要忘记关闭PrintWriter

            return;
        }

        if (StringUtils.isNotBlank(paramVo.getWjids())) {

            spcyBlgcclService.downZipZxclQyByWjIds(paramVo.getSqsxid(), paramVo.getWjids(), response);

        }else {

            List<String> typeList = CollectionUtil.newArrayList(
                    WjmlConstant.qydwjctz,
                    WjmlConstant.jczgclyq,
                    WjmlConstant.xcjcjl,
                    WjmlConstant.ljzlfk_cj,
                    WjmlConstant.ljzlfk_fcj,
                    WjmlConstant.cjcygzlfzdcb
            );

            spcyBlgcclService.downZipZxclQy(paramVo.getSqsxid(), typeList, response);
        }
    }

    @Log(title = "获取企业端-企业相关文件目录(办理材料)")
    @ApiOperation(value = "获取企业端-企业相关文件目录(办理材料)")
    @GetMapping(value = "queryWjMlByQy")
    public HttpResult queryWjMlByQy(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        List<String> typeList = CollectionUtil.newArrayList(
                WjmlConstant.qydwjctz,
                WjmlConstant.xcjcjl,
                WjmlConstant.xcjcqxjlb,
                WjmlConstant.ljzlfk_cj,
                WjmlConstant.ljzlfk_fcj,
                WjmlConstant.khmyddc,
                WjmlConstant.jczgclyq,
                WjmlConstant.zgcl);

        return HttpResult.ok(spcyBlgcclService.selectGroupWjjlByFtype(sqsxid, typeList));
    }

    @Log(title = "获取企业端-企业相关文件目录(整改材料)")
    @ApiOperation(value = "获取企业端-企业相关文件目录(整改材料)")
    @GetMapping(value = "queryWjzgMlByQy")
    public HttpResult queryWjzgMlByQy(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("事项参数为空！");
        }

        List<String> typeList = CollectionUtil.newArrayList(WjmlConstant.zgcl);

        return HttpResult.ok(spcyBlgcclService.selectGroupWjjlByFtype(sqsxid, typeList));
    }

    @Log(title = "获取APP端-方案制定函材料")
    @ApiOperation(value = "获取APP端-方案制定函材料")
    @GetMapping(value = "appFazdhFileList")
    public HttpResult appFazhFileList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("参数为空！");
        }

        return HttpResult.ok(spcyBlgcclService.selectAppFazhFileList(sqsxid));
    }

    @Log(title = "打包下载-检查方案材料")
    @ApiOperation(value = "打包下载-检查方案材料")
    @GetMapping(value = "downZipJcfaCl")
    public void downZipJcfaCl(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid, HttpServletResponse response) throws IOException {
        spcyBlgcclService.downZipJcfaCl(sqsxid, response);
    }

    @Log(title = "获取PC端-综合评定材料")
    @ApiOperation(value = "获取PC端-综合评定材料")
    @GetMapping(value = "zhpdclMlList")
    public HttpResult zhpdclMlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("参数为空！");
        }

        return HttpResult.ok(spcyBlgcclService.selectZhpdclMlList(sqsxid));
    }

    @Log(title = "获取综合评定审核件-相关打印签名数据")
    @ApiOperation(value = "获取综合评定审核件-相关打印签名数据")
    @GetMapping(value = "zhpdShjPrintData")
    public HttpResult zhpdShjPrintData(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        return HttpResult.ok(spcyBlgcclService.zhpdShjPrintData(sqsxid));
    }

    @Log(title = "查询日常监管-附件目录列表")
    @ApiOperation(value = "查询日常监管-附件目录列表")
    @GetMapping(value = "queryRcjgFjml")
    public HttpResult queryRcjgFjml(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("参数为空！");
        }

        return spcyBlgcclService.selectRcjgFjMlWithCommon(sqsxid);
    }

    @Log(title = "获取企业撤件申请材料目录")
    @ApiOperation(value = "获取企业撤件申请材料目录")
    @GetMapping(value = "qycjsqMlList")
    public HttpResult qycjsqMlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("参数为空！");
        }

        return HttpResult.ok(spcyBlgcclService.selectQycjsqclMlList(sqsxid));
    }

    @Log(title = "获取检查缺陷调整通知书目录")
    @ApiOperation(value = "获取检查缺陷调整通知书目录")
    @GetMapping(value = "jcqxtzMlList")
    public HttpResult jcqxtzMlList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("参数为空！");
        }

        return HttpResult.ok(spcyBlgcclService.selectGroupWjjlByFtype(sqsxid, CollectionUtil.newArrayList(WjmlConstant.jcqxtztzs)));
    }

    @Log(title = "获取上一次符合性检查报告列表")
    @ApiOperation(value = "获取上一次符合性检查报告列表")
    @GetMapping(value = "querySycjcbgList")
    public HttpResult querySycjcbgList(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("参数为空！");
        }

        return spcyBlgcclService.selectSycjcbgList(sqsxid);
    }

    @Log(title = "获取技术审评报告目录")
    @ApiOperation(value = "获取技术审评报告目录")
    @GetMapping(value = "jsspbgml")
    public HttpResult jsspbgml(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("参数为空！");
        }

        return HttpResult.ok(spcyBlgcclService.selectGroupWjjlByFtype(sqsxid, CollectionUtil.newArrayList(WjmlConstant.jsspbg)));
    }

    @Log(title = "获取综合评定报告目录")
    @ApiOperation(value = "获取综合评定报告目录")
    @GetMapping(value = "zgpdbgml")
    public HttpResult zgpdbgml(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("参数为空！");
        }

        return HttpResult.ok(spcyBlgcclService.selectGroupWjjlByFtype(sqsxid, CollectionUtil.newArrayList(WjmlConstant.zhpdbgs)));
    }
}
